package com.cryptoneedle.garden.api;

import com.bubbles.engine.common.core.result.Result;
import com.cryptoneedle.garden.service.dolphin.DolphinApiService;
import com.cryptoneedle.garden.service.dolphin.DolphinSourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>description:  </p>
 *
 * @author CryptoNeedle
 * @date 2025-11-05
 */
@Tag(name = "DolphinScheduler调度", description = "DolphinScheduler调度")
@RestController
@RequestMapping("/data-source")
public class DolphinSchedulerController {

    @Autowired
    private DolphinSourceService dolphinSourceService;

    @Autowired
    private DolphinApiService dolphinApiService;

    @PostMapping("/test")
    @Operation(summary = "test", description = "test")
    public Result<Long> test() {
        //dolphinSchedulerService.createProject();
        //ProjectApiClient projectApiClient = new ProjectApiClient(restTemplate);
        //projectApiClient.createProject("testtttt", "testtt");
        return Result.success(dolphinApiService.getUserCode());
    }

    @PostMapping("/database/{catalogName}/{databaseName}/dolphin-scheduler/workflow/seatunnel/generate")
    @Operation(summary = "生成数据库工作流", description = "生成数据库工作流")
    public Result<Void> generateSeatunnelWorkflow(
            @Parameter(description = "数据源目录名称") @PathVariable String catalogName,
            @Parameter(description = "数据库名称") @PathVariable String databaseName) {
        dolphinSourceService.generateSeatunnelWorkflow(catalogName, databaseName);
        return Result.success();
    }

    @PostMapping("/table/{catalogName}/{databaseName}/{tableName}/dolphin-scheduler/workflow/seatunnel/patch")
    @Operation(summary = "更新工作流", description = "更新数据源表的工作流")
    public Result<Void> patchSeatunnelWorkflow(
            @Parameter(description = "数据源目录名称") @PathVariable String catalogName,
            @Parameter(description = "数据库名称") @PathVariable String databaseName,
            @Parameter(description = "表名称") @PathVariable String tableName) {
        //dolphinSchedulerService.onlineDsWorkflow(catalogName, databaseName, tableName);
        return Result.success();
    }

    @PostMapping("/table/{catalogName}/{databaseName}/{tableName}/dolphin-scheduler/task-definition/seatunnel/patch")
    @Operation(summary = "更新任务定义", description = "更新数据源表的任务定义")
    public Result<Void> patchSeatunnelTaskDefinition(
            @Parameter(description = "数据源目录名称") @PathVariable String catalogName,
            @Parameter(description = "数据库名称") @PathVariable String databaseName,
            @Parameter(description = "表名称") @PathVariable String tableName) {
        //dolphinSchedulerService.taskDefinition(catalogName, databaseName, tableName);
        return Result.success();
    }
}